export default class Unix {
  static unixToTime(unix) {
    if (!unix) {
      return
    }
    unix = (unix + '').length <= 10 ? unix * 1000 : unix
    const date = new Date(unix)
    const month = (date.getMonth() + 1).toString()
    const day = date.getDate().toString()
    const hour = date.getHours().toString()
    const minutes = date.getMinutes().toString()
    const seconds = date.getSeconds().toString()
    return date.getFullYear() + '-' + (month.length === 2 ? month : '0' + month) + '-' + (day.length === 2 ? day : '0' + day) + ' ' + (hour.length === 2 ? hour : '0' + hour) + ':' + (minutes.length === 2 ? minutes : '0' + minutes) + ':' + (seconds.length === 2 ? seconds : '0' + seconds)
  }

  static unixToDate(unix) {
    if (!unix) {
      return
    }
    unix = (unix + '').length <= 10 ? unix * 1000 : unix
    const date = new Date(unix)
    const month = (date.getMonth() + 1).toString()
    const day = date.getDate().toString()
    return date.getFullYear() + '-' + (month.length === 2 ? month : '0' + month) + '-' + (day.length === 2 ? day : '0' + day)
  }

  static unixToMonths(unix) {
    if (!unix) {
      return
    }
    unix = (unix + '').length <= 10 ? unix * 1000 : unix
    const date = new Date(unix)
    const month = (date.getMonth() + 1).toString()
    return date.getFullYear() + '-' + (month.length === 2 ? month : '0' + month)
  }
}
